<template>
	<view class="content">
		<view style="background-color: #FFF;margin-top: 20rpx;">
			<u-tabs :list="dataList" :current="current" keyName='name' @click="tabClick"
				lineColor="#DD4949" :activeStyle="{color: '#DD4949'}"></u-tabs>
		</view>
		<view style="display: flex;flex-direction: column;" v-if="itemList.length>0">
			<itemListComponent @click='itemHandle' :itemList="itemList"></itemListComponent>
		</view>
		<view style="padding: 150rpx 0;" v-if='itemList.length==0'>
			<u-empty text="暂无数据" mode="list"></u-empty>
		</view>
	</view>
</template>

<script>
	import itemListComponent from '@/components/itemListComponent/index.vue'
	import { common } from "@/api/common.js"
	export default{
		components: {
			itemListComponent
		},
		props:{
		},
		data() {
			return {
				page: 1,
				size: 16,
				totalPage: 0,
				showEmpty: false,
				isLastPage: false,
				current: 0,
				dataList: [],
				itemList: []
			}
		},
		created() {
			this.getDataList()
		},
		methods:{
			tabClick(item){
				console.log('当前活动', item)
				this.tabsChange(item.index)
			},
			tabsChange(index){
				
				this.current = index;
				this.page = 1
				this.getItemList()
			},
			itemHandle(item) {
				this.$Router.push({
					name: 'itemDetail',
					params: {
						obj_id: item.id
					}
				})
			},
			getDataList(){
				common.operateActionGet('/merchant/genera/', {}).then(res => {
					if (res.data.code == 10000) {
						this.dataList = res.data.data.list
						this.tabsChange(this.current)
					}
				});	
			},
			getItemList(){
				common.operateActionGet('/merchant/itemForC/', {
					page: this.page,
					size: this.size,
					genera: this.dataList[this.current].id,
				}).then(res => {
					uni.stopPullDownRefresh();
					if(res.data.code == 10000){
						if (this.page == 1) {
							this.itemList = []
						}
						var list = res.data.data.list
						this.itemList = [...this.itemList, ...list]
						this.showEmpty = this.itemList.length < 1
						if (res.data.data.next) {
							this.page += 1
							this.isLastPage = false
						} else {
							this.isLastPage = true
						}
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	
</style>
